home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’90 / Busy Box / Sources / meter.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-14  |  1.9 KB  |  80 lines  |  [TEXT/KAHL]

  1. /* file meter.c
  2.     shows meters that bounce up and down
  3.     by LHL
  4. */
  5.  
  6. #include "busybox.h"
  7.  
  8. static int16 width, height, right, left, bottom, top;
  9. static int16 high1, high2, high3;    /* how high the bar was last */
  10. static Rect meter1, meter2, meter3;
  11. static Rect barRect;
  12.  
  13. void InitMeterObj(Rect *drawArea, int16 ID)
  14. {
  15.     barRect = *drawArea;
  16.     right = barRect.right;
  17.     left = barRect.left;
  18.     bottom = barRect.bottom;
  19.     top = barRect.top;
  20.     width = ((right - left) - 7) / 3;
  21.     height = bottom - top;
  22. /*    SetRect(&barRect, 0, 0, 500, 500); */
  23.     
  24.     SetRect(&meter1,left + 5, top + 2, (left + 2) + width, bottom - 2);
  25.     SetRect(&meter2,meter1.right + 4, top + 2, meter1.right + width, bottom - 2);
  26.     SetRect(&meter3,meter2.right + 4, top + 2, meter2.right + width, bottom - 2);
  27.  
  28. }    /* InitMeterObj    */
  29.  
  30.  
  31. void DrawMeterObj(int16 ID)
  32. {
  33.     static Rect OneUp, TwoUp, ThreeUp;
  34.     int16 fudge1, fudge2, fudge3;
  35.     static lastTime1, lastTime2, lastTime3;
  36.  
  37.     FrameRect(&meter1);
  38.     FrameRect(&meter2);
  39.     FrameRect(&meter3);
  40.     
  41.     fudge1 = abs(Random() % height) + 3;
  42.     fudge2 = abs(Random() % height) + 3;
  43.     fudge3 = abs(Random() % height) + 3;    
  44.     
  45.     if (lastTime1 > fudge1) {
  46.         SetRect(&OneUp, meter1.left + 1, fudge1, meter1.right - 1, meter1.bottom - 1);
  47.         FillRect(&OneUp, gray);
  48.     }
  49.     else {
  50.         SetRect(&OneUp, meter1.left + 1, lastTime1 - 1, meter1.right - 1, fudge1 - 1);
  51.         FillRect(&OneUp, white);
  52.     }
  53.  
  54.  
  55.     if (lastTime2 > fudge2) {
  56.         SetRect(&TwoUp, meter2.left + 1, fudge2, meter2.right - 1, meter2.bottom - 1);
  57.         FillRect(&TwoUp, gray);
  58.     }
  59.     else {
  60.         SetRect(&TwoUp, meter2.left + 1, lastTime2 - 1, meter2.right - 1, fudge2 - 1);
  61.         FillRect(&TwoUp, white);
  62.     }
  63.  
  64.  
  65.     if (lastTime3 > fudge3) {
  66.         SetRect(&ThreeUp, meter3.left + 1, fudge3, meter3.right - 1, meter3.bottom - 1);
  67.         FillRect(&ThreeUp, gray);
  68.     }
  69.     else {
  70.         SetRect(&ThreeUp, meter3.left + 1, lastTime3 - 1, meter3.right - 1, fudge3 - 1);
  71.         FillRect(&ThreeUp, white);
  72.     }
  73.  
  74.     lastTime1 = fudge1;
  75.     lastTime2 = fudge2;
  76.     lastTime3 = fudge3;
  77.  
  78.  
  79. }    /* DrawMeterObj    */
  80.